<?php
        define('admin_ROOT',  $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR);
	include admin_ROOT .  'public/class_dbmysql.php';
	include admin_ROOT .  'datacache/public.php';
	$login = $_GET['login'];
	$password1 = $_GET["password"];
        $lng = $_GET['lng'];
        $startDate =  isset($_GET['beginDate']) ? $_GET['beginDate']: date("Y-m-d",strtotime("last month"));
	$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : date('Y-m-d');
                
                
	if(!isset($login) || !isset($password1)) {
		echo "<script>alert('登录失败.');history.go(-1);</script>";
		exit;
	}
	//本地数据库连接
	
	$db = new dbmysql();
	$db->connect(db_host, db_user, db_pw, db_name, db_charset, db_link);
	$db_table = db_prefix . 'regular_member_class';
	$password = md5($password1);
	$db_where =  "name='$login' AND password='$password'";
	$sql = "SELECT *  FROM " . $db_table . " WHERE " .$db_where;
	$rs = $db->query($sql);
	$userinfo = $db->fetch_assoc($rs);
	$count = $db->num_rows($rs);
	if($count <= 0) {
		echo "<script>alert('用户名/密码错误');history.go(-1);</script>";
		exit;
	}
	//获取卓越账户管理组
	$groupStr = '"' . rtrim($userinfo['managergroup'], ",") . '"';
	$groupStr = str_replace(',','","',$groupStr);
        $db = new dbmysql();
		$db->connect(report_host, report_user, report_pwd, report_dbname, 'utf8', 1);
		$sql = 'SELECT u.login"交易账户",u.name"姓名",u.balance"余额",ROUND(u.equity,2)"净值",ROUND(SUM(d.PROFIT),2)"平仓盈亏",u.margin"占用保证金"
				FROM mt4_users AS u 
				LEFT JOIN mt4_daily AS d
				ON u.login=d.login AND DATE(d.time) >= "' .$startDate. '" AND DATE(d.time) <= "' .$endDate. '" 
				WHERE u.group IN (' . $groupStr . ') 
				GROUP BY u.LOGIN';
        $rs = $db->query($sql);
			$blancesSum = 0;
			$equitySum = 0;
			$profitSum = 0;
			while ($rsList = $db->fetch_assoc($rs)) {
				$profit = empty($rsList["平仓盈亏"]) ? "0.00" : $rsList["平仓盈亏"];
				$blancesSum += $rsList["余额"];
				$equitySum += $rsList["净值"];
				$profitSum += $profit;
				echo '<tr align="center" bgcolor="#cccccc">
		              <td style="font-size:15px">' . $rsList["交易账户"] .'</td>
				      <td style="font-size:15px">' . $rsList["姓名"] .'</td>
		              <td style="font-size:15px">' . $rsList["余额"] .'</td>
		              <td style="font-size:15px">' .$rsList["净值"] .'</td>
                              <td style="font-size:15px">' . $profit .'</td>
					  <td style="font-size:15px">' .$rsList["占用保证金"] .'</td>
					  </tr>';

			}
                        echo '<tr align="center" bgcolor="#cccccc">
		              <td style="font-size:15px">' . ($lng == 'cn'?'合计':'Total') . '</td>
			      <td style="font-size:15px"></td>
		              <td style="font-size:15px">' . $blancesSum . '</td>
		              <td style="font-size:15px">' . $equitySum . '</td>
                              <td style="font-size:15px">' . $profitSum . '</td>
					  <td style="font-size:15px"></td>
					  </tr>';
                        
		
		$db->close();
?>
